import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'

export default defineConfig({
  plugins: [react()],
  server: {
    port: 3002,
    cors: true,
    origin: 'http://localhost:3002',
    headers: {
      'Access-Control-Allow-Origin': '*'
    },
    hmr: false
  },
  base: 'http://localhost:3002/',
  // 添加构建配置
  build: {
    minify: false,
    cssCodeSplit: false,
    rollupOptions: {
      output: {
        format: 'umd',
        entryFileNames: 'assets/[name].js',
        chunkFileNames: 'assets/[name].js',
        assetFileNames: 'assets/[name].[ext]'
      }
    }
  },
  // 配置依赖优化选项
  optimizeDeps: {
    include: ['react', 'react-dom'],
    // 配置 esbuild 选项
    esbuildOptions: {
      define: {
        global: 'globalThis'
      }
    }
  },
  // 添加预览配置
  preview: {
    port: 3002,
    cors: true,
    headers: {
      'Access-Control-Allow-Origin': '*'
    }
  }
})